<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@include file="/WEB-INF/base.jspf"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="/css/loaders.min.css" />
<title>香港六合彩开奖设置</title>
<style type="text/css">
	.p-c-flexwrapper {
		display:flex;
		align-items:center;
		margin-right:16px;
		margin-bottom:16px;
	}
	.p-c-flexwrapper > span {
		width:80px;
	}
		.modal-dialog {
		max-width: 1000px;
	}
	.p-c-flexwrapper > #input-i-period {
		width:auto;
		flex-grow:1;
	}
	.p-c-flexwrapper > #input-i-period1 {
		width:auto;
		flex-grow:1;
	}
	.input-c-lotterNumber {
		width:50px;
		height:50px;
		margin-right:12px;
	}
	table th,table tr,table td {
text-align: center;
vertical-align:middle;
}
</style>
</head>
<body>
	<div style="display:flex;justify-content:flex-end;"><button  class="save btn btn-primary btn-lg" >预设下期开奖期号</button></div>
<!-- 	<p style="font-weight:bold;color:red;">注:请认真多次核对开奖号码及期号,一但添加后,香港六合彩会立即开奖,无法撤回</p> -->
	<table id="table-i-qqAccountList" class="table table-striped table-bordered table-hover" style="margin-top: 20px;">
		<thead>
			<tr>
			<th style="display:none;"></th>
			<th>彩种名称</th>
			<th>开奖期号</th>
			<th>下期期号</th>
			<th>开奖号码</th>
			<th>预计派奖时间</th>
			<th>派奖时间</th>
			<th>下期时间</th>
			<th>开奖状态</th>
			<th>派奖操作</th>
			</tr>
		</thead>
		<tbody>
		</tbody>
	</table>
		<div class="modal fade" id="addAndEditModal" tabindex="-1" role="dialog" aria-labelledby="addAndEditModal" aria-hidden="true">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
						<h4 class="modal-title" id="myModalLabel">新增/修改</h4>
					</div>
					<div class="modal-body">
					<input id="input-i-id" hidden="hidden" class="input-auto" />
					<form>
						<p class="p-c-flexwrapper" style="color: red;">注意:下期开奖期号和当期开奖期号预设以后将不能改变因为用户已经下注请谨慎填写!</p>
						<p class="p-c-flexwrapper"><span>开奖期号：</span><input id="input-i-period"  placeholder="开奖期号" ditype="number" required class="input-auto form-control" /></p>
						<p class="p-c-flexwrapper"><span>下期期号：</span><input  id="input-i-period1"  placeholder="下期期号" ditype="number" required class="input-auto form-control" /></p>
						 <div class="p-c-flexwrapper"><span>开奖时间：</span>
					      <div class="layui-input-inline">
					        <input type="text"  placeholder="当期开奖时间" class="layui-input" required id="date">
					      </div>
						</div>
						 <div class="p-c-flexwrapper"><span>下期时间：</span>
					      <div class="layui-input-inline">
					        <input type="text" placeholder="下期开奖时间" class="layui-input" required id="date1">
					      </div>
						</div>
					</form>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-primary" id="button-i-addNewQQNumber">提交更改</button>
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					</div>
				</div>
			</div>
	</div>
	
	<div class="modal fade" id="updAndEditModal" tabindex="-1" role="dialog" aria-labelledby="updAndEditModal" aria-hidden="true">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
						<h4 class="modal-title" id="myModalLabel">新增/修改</h4>
					</div>
					<div class="modal-body">
					<input id="input-i-id" hidden="hidden" class="input-auto" />
					<form>
		             <p class="p-c-flexwrapper"><span>开奖号码：</span>
		            		<input class="form-control input-c-lotterNumber" required />
		            		<input class="form-control input-c-lotterNumber" required />
		            		<input class="form-control input-c-lotterNumber" required />
		            		<input class="form-control input-c-lotterNumber" required />
		            		<input class="form-control input-c-lotterNumber" required />
		            		<input class="form-control input-c-lotterNumber" required />
		            		<span style="width:8px;height:50px;margin-right:12px;display:inline-flex;justify-content:center;align-items:center;font-size:30px;">+</span>
		            		<input class="form-control input-c-lotterNumber" required />
		            	</p> 
					</form>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-primary" id="button-i-addNewQQNumber2">提交更改</button>
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					</div>
				</div>
			</div>
		</div>
	
	
<div class="modal fade" id="noticeModal" tabindex="-1" role="dialog" aria-labelledby="noticeModal" aria-hidden="true">
    <div class="modal-dialog class-fake-alert">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            </div>
            <div class="modal-body" ></div>
            <div class="modal-footer">	      
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>   

<div class="modal fade" id="confirmKaiJiangModal" tabindex="-1" role="dialog" aria-labelledby="confirmKaiJiangModal" aria-hidden="true">
    <div class="modal-dialog class-fake-alert">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            </div>
            <div class="modal-body" >是否确认派奖</div>
            <div class="modal-footer">	      
           	    <button type="button" class="btn btn-primary" id="button-i-querenpaijiang">确认</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>   	
<script type="text/javascript" src="/js/loaders.css.js"></script>			
	<script type="text/javascript" src="/js/zhengzeTools.js"></script>
	<script type="text/javascript">
	//xglhcDelete
	
	
	layui.use('laydate', function(){
		  var laydate = layui.laydate;
		  laydate.render({
		    elem: '#date',
		    type: 'datetime'
		  });
		  laydate.render({
			    elem: '#date1',
			    type: 'datetime'
			  });
		});
		$(".save").on("click", function(e) {
			$("#input-i-period").attr("disabled",false)
			$("#input-i-period1").attr("disabled",false)
			$("#addAndEditModal").attr("data-type", "add")
			$("#addAndEditModal").modal("show")
		})
		$("#table-i-qqAccountList").DataTable({
	      // "bPaginate": true,
	      "bLengthChange": true,      
	      "bSort": false,
	      // "bInfo": true,
	      "bAutoWidth": false,
//		         "bServerSide":true,
	      'aLengthMenu':[10, 20],
	       "searching": false,
	       "dom": "t<'tableinfo'i<'tableSearch'p>l>",
//		    "searching": true,l
	       "language": {//语言设置  
	            "lengthMenu": "每页显示 _MENU_ 条记录",     
	            "zeroRecords": "没有检索到数据",     
	            "sInfo": "当前显示 _START_ 到 _END_ 条，共 _TOTAL_ 条记录",     
	            "info": "没有数据",     
	            "oPaginate": {     
	                "sFirst": "首页",     
	                "sPrevious": "前一页",     
	                "sNext": "后一页",     
	                "sLast": "尾页"    
	          	},
	            "search":"搜索:",
	            "infoFiltered":   "(从  _MAX_ 记录中搜索出结果)",
	            "infoEmpty":      "没有找到匹配的信息",
	         },
	         "ajax": {
	        	 "type": "POST",
	        	 "url": "/czgl/hongKongLotteryPresetRecord.do",
	        	 "dataSrc": function(json) {
	        		 for (var i = 0; i < json.data.length; i++) {
	        			 var item = json.data[i]
	        			 if (item.state === "已开奖") {
	        				 item.btns = ""
	        			 } else {
	        				 item.btns = "<button class='btn btn-success btn-sm btn-c-xiugaizhongjianghaoma' style='margin-right:32px;'>编辑开奖号码</button><button class='btn btn-warning btn-sm btn-editKaiJiang' style='margin-right:32px;'>修改</button><button class='btn btn-info btn-sm btn-c-paijiangBtn'>开始派奖</button>"
	        			 }
	        		 }
	        		 return json.data
	        	 }
	         },
	         "columns": [
						 {"data": "id", "className": "hidden-td id-edit-td"},
	                     {"data": "gameNameInChinese", "className": "gameNameInChinese-edit-td"},
	                     {"data": "period", "className": "period-edit-td"},
	                     {"data": "nextperiod", "className": "nextperiod-edit-td"},
	                     {"data": "lotternumber", "className": "lotternumber-edit-td"},
	                     {"data": "openTime", "className": "openTime-edit-td"},
	                     {"data": "paijtime", "className": "paijtime-edit-td"},
	                     {"data": "nextStopOrderTimeEpoch", "className": "nextStopOrderTimeEpoch-edit-td"},
	                     {"data": "state", "className": "state-edit-td"},
	                     {"data":  "btns",},
	                 ]        
	   		 })		
	   		 insertSearchBtn()
			$('#addAndEditModal').on('hidden.bs.modal', function () {
				if ($("#addAndEditModal").attr("data-type") == "edit") {
					$("#addAndEditModal form")[0].reset()
				}
			})
			
			function mixLooterNumber() {
				var result = ""
				$("#updAndEditModal .input-c-lotterNumber").each(function(index, element) {
					result += element.value + ","
				})
				return result
			}
		
			var numZhengZe = /^[0-9]+$/
			
			var obj = {
				btnName: "#button-i-addNewQQNumber2",
				divName: "#updAndEditModal",
	            callback: function() {
	            	var allNumberInputs = $("#updAndEditModal .input-c-lotterNumber")
	            	var flag = true
	            	var isRepeat = true
	            	
	            	outFor:
	            	for (var i = 0; i < allNumberInputs.length; i++) {
	            		var item = allNumberInputs[i]
	      				var specialValue = item.value 
	            		if (specialValue.length != 2 || !numZhengZe.test(specialValue) || Number(specialValue) > 49) {
							flag = false	            			
	            		}
	            		for (var j = 0; j < allNumberInputs.length; j++) {
	            			var item2 = allNumberInputs[j]
	            			if (j == i) {continue}
	            			if (item2.value == item.value) {
	            				isRepeat = false
	            				break outFor
	            			}
	            		}
	            	}
	            	if (!flag) {
	            		return "开奖号码输入有误"
	            	}
	            	if (!isRepeat) {
	            		return "开奖号码不得重复"
	            	}
	            	return "ok"
	            }
			}
			
			checkFormMethod(obj, function() {
				var newRequest = {
					url: "/czgl/updateHongKongLotteryCheckNum.do",
					type: "post",
					data: {
						id: $("#input-i-id").val(),
						lotternumber: mixLooterNumber(),
						period: $("#updAndEditModal").attr("data-qihao"),
						gameNameInChinese:$("#updAndEditModal").attr("data-gameNameInChinese")
					},
					success: function(data) {
						var newData = JSON.parse(data)
						showNoticeModal("操作成功！")
						$('#updAndEditModal').modal("hide")
						$("#updAndEditModal form")[0].reset()
						var table = $("#table-i-qqAccountList").DataTable()
						table.ajax.reload()
					},
					error: function(status) {
					}
				}
				ajax(newRequest)
			})	
			
			
			
			var obj2 = {
				btnName: "#button-i-addNewQQNumber",
				divName: "#addAndEditModal",
				isRegArray: [
		             {inputValue: function() {
		            	 return $("#input-i-period").val()
		             }, regValue:/^[0-9]+$/, noticeText:"无效的期号"},			             
	            ],
			}
			
			var ajaxObj = {
				"add": "/czgl/hongKongLotteryPreset.do",
				"edit": "/czgl/updateHongKongLotteryChekcInfo.do",
			}
			
			checkFormMethod(obj2, function() {
				if($("#date").val() == '' || $("#date1").val() == '' || $("#input-i-period").val() == '' || $("#input-i-period1").val() == ''){
					showNoticeModal("当期期号和下期期号和当期开奖时间和下期开奖时间不能为空！")
					return	
				}
				var sendType = $("#addAndEditModal").attr("data-type")
				var newRequest = {
					type: "post",
					url: ajaxObj[sendType],
					data: {
						openTime:$("#date").val(),
						nextStopOrderTimeEpoch: $("#date1").val(),
						period: $("#input-i-period").val(),
						nextperiod: $("#input-i-period1").val(),
						cname: "xg6hc",
						lotternumber: "",
						cnames: "香港六合彩",
						type: "0",
					},
					success: function(data) {
						var newData = JSON.parse(data)
						if (newData.data === 10) {
							showNoticeModal("操作失败,期号已存在")
							return							
						}
						if(newData.data == 11){
							showNoticeModal("操作失败,当期期号必须和上期的下期期号对应！因为用户可能已下注,如果不一致开奖则会出现异常")
							return	
						}
						if (sendType === "edit" && newData.data != 1) {
							showNoticeModal("操作失败")
							return
						}
						showNoticeModal("操作成功！")
						$('#addAndEditModal').modal("hide")
						$("#addAndEditModal form")[0].reset()
						var table = $("#table-i-qqAccountList").DataTable()
						table.ajax.reload()
					},
					error: function(status) {
					}
				}
				if (sendType === "edit") {
					newRequest.data.period = $("#addAndEditModal").attr("data-qihao")
				}
				ajax(newRequest)
			})				
			
			$("#table-i-qqAccountList").on("click", ".btn-c-xiugaizhongjianghaoma", function(e) {
				var $tr = $(e.currentTarget).closest("tr")
				$("#input-i-id").val($tr.find(".id-edit-td").text())
				var lotterNum = $tr.find(".lotternumber-edit-td").text()
				if (lotterNum != "") {
					lotterNum = lotterNum.split(",")
				}
				var $allLoterInputs = $(".p-c-flexwrapper .input-c-lotterNumber")
				for (var i = 0; i < lotterNum.length; i++) {
					$allLoterInputs.eq(i).val(lotterNum[i])
				}
				$("#updAndEditModal").attr("data-qihao", $tr.find(".period-edit-td").text())
				$("#updAndEditModal").attr("data-gameNameInChinese", $tr.find(".gameNameInChinese-edit-td").text())
				$("#updAndEditModal").modal("show")
			})

			$("#table-i-qqAccountList").on("click", ".btn-c-paijiangBtn", function(e) {
				var $tr = $(e.currentTarget).closest("tr")
				if ($tr.find(".lotternumber-edit-td").text() == "") {
					showNoticeModal("请先填写开奖号码再进行派奖")
					return
				}
				$("#confirmKaiJiangModal").attr("data-qihao", $tr.find(".period-edit-td").text())
				$("#confirmKaiJiangModal").attr("data-id", $tr.find(".id-edit-td").text())
				$("#confirmKaiJiangModal").attr("data-gameNameInChinese", $tr.find(".gameNameInChinese-edit-td").text())
				$("#confirmKaiJiangModal").modal("show")
			})	
			$("#table-i-qqAccountList").on("click", ".btn-editKaiJiang", function(e) {
				var $tr = $(e.currentTarget).closest("tr")
				$("#input-i-period").val($tr.find(".period-edit-td").text())
				$("#input-i-period1").val($tr.find(".nextperiod-edit-td").text())
				$("#date").val($tr.find(".openTime-edit-td").text())
				$("#date1").val($tr.find(".nextStopOrderTimeEpoch-edit-td").text())
				$("#addAndEditModal").attr("data-type", "edit")
				$("#addAndEditModal").attr("data-qihao", $tr.find(".period-edit-td").text())
				$("#input-i-period").attr("disabled","disabled")
				$("#input-i-period1").attr("disabled","disabled")
				$("#addAndEditModal").modal("show")
			})
			$("#button-i-querenpaijiang").on("click", function(e) {
				var newRequest = {
						type: "post",
						url: "/czgl/updateHongKongLotteryCheck.do",
						data: {
							cname: "xg6hc",
							period: $("#confirmKaiJiangModal").attr("data-qihao"),
							id: $("#confirmKaiJiangModal").attr("data-id"),
							gameNameInChinese:$("#confirmKaiJiangModal").attr("data-gameNameInChinese")
						},
						success: function(data) {
							var newData = JSON.parse(data)
							showNoticeModal("操作成功！")
							$('#confirmKaiJiangModal').modal("hide")
							var table = $("#table-i-qqAccountList").DataTable()
							table.ajax.reload()
						},
						error: function(status) {
						}
					}
					ajax(newRequest)				
			})
			//confirmKaiJiangModal
			
	</script>
</body>
</html>